package com.JumpAndJump.controller;

import com.JumpAndJump.common.ServerResponse;
import com.JumpAndJump.pojo.User;
import com.JumpAndJump.service.IScoreService;
import com.JumpAndJump.vo.Score;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2018/1/7.
 */
@Controller
@RequestMapping("/score/")
public class GameController {

    @Autowired
    private IScoreService iScoreService;

    @RequestMapping(value = "searchByID.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<Score> getScore(int ID, HttpSession session){
        ServerResponse<Score> response =iScoreService.getScore(ID);
        if(response.isSuccess()){
            session.setAttribute("score",response.getData());
        }
        return response;
    }

    @RequestMapping(value = "updateScore.do",method = RequestMethod.POST)
    @ResponseBody
    public  ServerResponse<Score> update(int ID ,int score){
        ServerResponse<Score> response =iScoreService.updateScore(ID,score);
      return response;
    }

    @RequestMapping(value = "scoreList.do",method = RequestMethod.POST)
    @ResponseBody
    public  ServerResponse<PageInfo> getScoreList(@RequestParam(value = "pageNum",defaultValue = "1")int pageNum, @RequestParam(value = "pageSize",defaultValue = "10")int pageSize){
        ServerResponse<PageInfo> response =iScoreService.getScoreList(pageNum,pageSize);
        return response;
    }

    @RequestMapping(value = "getPersonList.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<Score> getPersonList(int ID){
        ServerResponse<Score> response =iScoreService.getPersonList(ID);
        return response;
    }






}
